<?php

/**
 * iWebkit for MyBB, provide a mobile friendly interface.
 * Copyright (C) 2010  Christopher John Jackson
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

//We need to check if you're on an iPhone or not...
/*if (!preg_match("#iPhone#", $_SERVER['HTTP_USER_AGENT'])) {
	//Find top-level of URI
	//$url = 'http'. ($_SERVER['HTTPS'] ? 's' : null) .'://'. $_SERVER['HTTP_HOST'];
	//Forward you out of here
	//header("Location: $url");
}*/
//Let's set some MyBB things up, first
define('IN_MYBB', 1);
//header('Cache-Control: no-store, no-cache, must-revalidate'); 
header('Cache-Control: post-check=0, pre-check=0', FALSE); 
header('Pragma: no-cache');

if(!defined('MYBB_ROOT'))
{
	define('MYBB_ROOT', dirname(dirname(__FILE__))."/");
}

require MYBB_ROOT."iphone/includes/global.php";
require MYBB_ROOT."inc/class_parser.php";
$parser = new postParser();
// Load global language phrases
$lang->load("index");
$plugins->run_hooks("ae_mobile_start");

//$postdata = "";

function curPageURL() {
	$pageURL = 'http';
	if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
	$pageURL .= "://";
	if ($_SERVER["SERVER_PORT"] != "80") {
		$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
	} else {
		$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
	}
	return $pageURL;
}
function strTrim($text, $len) {
	if (strlen($text) >= $len) {
		// Change to the number of characters you want to display
		$chars = $len - 3;
		$text = $text." ";
		$text = substr($text,0,$chars);
		$text = substr($text,0,strrpos($text,' '));
		$text = $text."...";
		return $text;
	}
	else return $text;
}

//We need a session for the previous page
session_start();

$pagedata = null;

require MYBB_ROOT."iphone/includes/commandAndFunction.class.php";

$object = new commandAndFunction();
if(method_exists($object, 'command_'.$action)){
    $action = 'command_'.$action;
    $object->$action();
    $pagedata = $object->getData();
} else {
    $object->_default();
    $pagedata = $object->getData();
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type" />
<meta content="minimum-scale=1.0, width=device-width, maximum-scale=0.6667, user-scalable=no" name="viewport" />
<link href="<?php echo $mybb->settings['bburl'] ?>/iphone/css/style.css" rel="stylesheet" type="text/css" />
<script src="<?php echo $mybb->settings['bburl'] ?>/iphone/javascript/functions.js" type="text/javascript"></script>
<title><?php echo $mybb->settings['bbname'] ?></title>
<meta content="mybb" name="keywords" />
<meta content="description" name="description" />
</head>
<body>
<div id="topbar">
<?php	
echo $pagedata[topbar];
?>
<div id="title"><?php echo $mybb->settings['bbname']; ?></div>
<?php
if($mybb->user['uid'] > 0)
{
	?>
	<div id="rightnav">
	<a href="<?php echo $archiveurl.'/index.php/'; ?>signout.html">Sign Out</a>
	</div>
	<?php
}
else
{
	?>
	<div id="rightnav">
	<a href="<?php echo $archiveurl.'/index.php/'; ?>signin.html">Sign In</a>
	</div>
	<?php
}
?>
</div>
<div id="content">
<?php echo $pagedata['content']; ?>
</div>
<div id="footer">
<?php
if($mybb->user['uid'] > 0)
{
	?>
	<a class="noeffect">Signed in as <?php echo $mybb->user['username']; ?> (<u><a href="signout.html">Sign out</a></u>)</a><br />
	<?php
}
else
{
	?>
	<a class="noeffect">You are not <u><a href="signin.html">signed in</a></u></a><br />
	<?php
}
?>
<!-- please keep this line of text for three reasons: to help us, to thank us and just because it is cool-->
<a class="noeffect" href="http://iwebkit.net">Powered by iWebKit</a></div>
</body>
</html>
<?php $_SESSION['back'] = htmlentities($_SERVER['REQUEST_URI']); ?>
